package com.maxatime.web.controller;

import java.util.HashMap;
import java.util.Map;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSONObject;
import com.maxatime.common.constant.BusinessContents;
import com.maxatime.pojo.entity.ExamPlace;
import com.maxatime.service.ExamplaceService;
import com.maxatime.util.MyContent;



@Controller
@RequestMapping("/ExamPlace")
//@RestController
public class ExamPlaceController {
	
	@Autowired
	ExamplaceService examplaceService;
	
	/**
	 * 
	 * @Title: quest   
	 * @Description: TODO(考试地点管理)   
	 * @param: @param jsonStr
	 * @param: @return      
	 * @return: Map<String,Object>      
	 * @throws   
	 * @author: ssb    
	 * @date:   2024年2月26日 上午11:40:21   
	 * @version V1.0
	 */
	@RequestMapping("/quest")
	@ResponseBody
	public Map<String, Object> quest(@RequestBody String jsonStr){
		JSONObject jsonObj = JSONObject.parseObject(jsonStr);
		
		String examPlaceName = jsonObj.getString("examPlaceName");
		int pageNum = jsonObj.getIntValue("pageNum");
		int pageSize = jsonObj.getIntValue("pageSize");
		ExamPlace examPlace = new ExamPlace();
		examPlace.setExamPlaceName(examPlaceName);
		examPlace.setPageNum(pageNum);
		examPlace.setPageSize(pageSize);
		
		Map<String, Object> m = examplaceService.list(examPlace);
		m.put(BusinessContents.CODE, "0000");
		m.put(BusinessContents.MSG, "交易成功");
		m.put(BusinessContents.DATA, m.get("examPlace"));
		m.put("pageInfo", m.get("pageInfo"));
		return m;
	}
	
	@RequestMapping("/save")
	@ResponseBody
	public Map<String, Object> save(@RequestBody ExamPlace examPlace){
		Map<String, Object> m = new HashMap<>();
		examplaceService.insertSelective(examPlace);
		m.put(MyContent.CODE, "1111");
		m.put(MyContent.MSG, "新增成功");
		return m;
	}
	
	@RequestMapping("/del")
	@ResponseBody
	public Map<String, Object> del(@RequestBody String jsonStr){
		JSONObject jsonObj = JSONObject.parseObject(jsonStr);
		int pkId = jsonObj.getInteger("pkId");
		Map<String, Object> m = new HashMap<>();
		examplaceService.deleteByPrimaryKey(pkId);
		m.put(MyContent.CODE, "2222");
		m.put(MyContent.MSG, "删除成功");
		return m;
	}
	
	@RequestMapping("/find")
	@ResponseBody
	public Map<String, Object> find(@RequestBody String jsonStr){
		JSONObject jsonObj = JSONObject.parseObject(jsonStr);
		int pkId = jsonObj.getInteger("pkId");
		Map<String, Object> m = new HashMap<>();
		ExamPlace examPlace= examplaceService.find(pkId);
		m.put(MyContent.CODE, "3333");
		m.put(MyContent.MSG, "反显成功");
		m.put(MyContent.DATA, examPlace);
		return m;
	}
	
	@RequestMapping("/update")
	@ResponseBody
	public Map<String, Object> update(@RequestBody ExamPlace examPlace){
		Map<String, Object> m = new HashMap<>();
		examplaceService.updateByPrimaryKeySelective(examPlace);
		m.put(MyContent.CODE, "4444");
		m.put(MyContent.MSG, "修改成功");
		return m;
	}
}
